﻿using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;

namespace QDP.Platform.Silverlight.Storyboards
{
    /// <summary>
    /// 
    /// </summary>
    public class MoveZoomStyle : IStoryboard
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Element"></param>
        /// <returns></returns>
        public Storyboard Showing(UIElement Element)
        {
            Storyboard story = new Storyboard();
            Element.Projection = new PlaneProjection();
            DoubleAnimationUsingKeyFrames frames = new DoubleAnimationUsingKeyFrames();

            frames.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero), Value = -2000 });
            frames.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(300)), Value = 0 });
            Storyboard.SetTargetProperty(frames, new PropertyPath("(UIElement.Projection).(PlaneProjection.GlobalOffsetZ)")); 
            Storyboard.SetTarget(frames, Element);
            story.Children.Add(frames);

            frames = new DoubleAnimationUsingKeyFrames();

            frames.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero), Value = 0 });
            frames.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(300)), Value = 1 });
            Storyboard.SetTargetProperty(frames, new PropertyPath("UIElement.Opacity"));
            Storyboard.SetTarget(frames, Element);
            story.Children.Add(frames);


            frames = new DoubleAnimationUsingKeyFrames();

            frames.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero), Value = -90 });
            frames.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(300)), Value = 0 });
            Storyboard.SetTargetProperty(frames, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationY)"));
            Storyboard.SetTarget(frames, Element);
            story.Children.Add(frames);

            frames = new DoubleAnimationUsingKeyFrames();
            frames.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero), Value = -90 });
            frames.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(300)), Value = 0 });
            Storyboard.SetTargetProperty(frames, new PropertyPath("(UIElement.Projection).(PlaneProjection.GlobalOffsetX)"));
            Storyboard.SetTarget(frames, Element);
            story.Children.Add(frames);
            
            return story;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Element"></param>
        /// <returns></returns>
        public Storyboard Closing(UIElement Element)
        {
            Storyboard story = new Storyboard();
            Element.Projection = new PlaneProjection();
            DoubleAnimation animation = new DoubleAnimation();
            animation.Duration = new Duration(TimeSpan.FromMilliseconds(300));
            animation.To = -2000;
            Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.Projection).(PlaneProjection.GlobalOffsetZ)"));
            Storyboard.SetTarget(animation, Element);
            story.Children.Add(animation);

            animation = new DoubleAnimation();
            animation.Duration = new Duration(TimeSpan.FromMilliseconds(300));
            animation.To = 0;
            Storyboard.SetTargetProperty(animation, new PropertyPath("UIElement.Opacity"));
            Storyboard.SetTarget(animation, Element);
            story.Children.Add(animation);

            animation = new DoubleAnimation();
            animation.Duration = new Duration(TimeSpan.FromMilliseconds(300));
            animation.To = -90;
            Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationY)"));
            Storyboard.SetTarget(animation, Element);
            story.Children.Add(animation);

            animation = new DoubleAnimation();
            animation.Duration = new Duration(TimeSpan.FromMilliseconds(300));
            animation.To = -90;
            Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.Projection).(PlaneProjection.GlobalOffsetX)"));
            Storyboard.SetTarget(animation, Element);
            story.Children.Add(animation);

            return story;
        }
    }
}
